package org.gurms.service.system.impl;

import java.util.ArrayList;
import java.util.List;

import org.gurms.common.util.ReflectionUtil;
import org.gurms.dao.po.system.SysMenu;
import org.gurms.dao.system.SysMenuDao;
import org.gurms.service.PojoConvert;
import org.gurms.service.dto.Page;
import org.gurms.service.dto.PropertyFilter;
import org.gurms.service.dto.system.MenuDto;
import org.gurms.service.system.SysMenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class SysMenuServiceImpl implements SysMenuService{

	private Logger logger = LoggerFactory.getLogger(SysMenuServiceImpl.class);

	@Autowired
	private SysMenuDao sysMenuDao;

	public SysMenuDao getSysMenuDao() {
		return sysMenuDao;
	}

	public void setSysMenuDao(SysMenuDao sysMenuDao) {
		this.sysMenuDao = sysMenuDao;
	}

	@Transactional(readOnly = true)
	public MenuDto get(MenuDto menuDto){
		SysMenu menu = sysMenuDao.get(menuDto.getMenuid());
		return PojoConvert.convert(menu);
	}
	
	@Transactional(readOnly = true)
	public List<MenuDto> getList(String id){
		SysMenu menu = sysMenuDao.get(id);
		List<MenuDto> list = new ArrayList<MenuDto>();
		PojoConvert.convertTreeList(list, menu);
		return list;
	}
	
	public void save(MenuDto MenuDto) {
	}

	public void update(MenuDto MenuDto) {
	}

	public void delete(MenuDto MenuDto) {
	}

	@Transactional(readOnly = true)
	public Page<MenuDto> getAll(Page<MenuDto> page) {
		// TODO Auto-generated method stub
		return null;
	}

	@Transactional(readOnly = true)
	public Page<MenuDto> search(Page<MenuDto> pageDto, List<PropertyFilter> filters) {
		// TODO Auto-generated method stub
		Page<SysMenu> page = new Page<SysMenu>();
		ReflectionUtil.getDozer().map(pageDto, page);
//		page = sysMenuDao.findPage(page, filters);
		
		List<SysMenu> poList = page.getResult();
		List<MenuDto> dtoList = new ArrayList<MenuDto>();
		for(SysMenu po : poList){
			dtoList.add((MenuDto)ReflectionUtil.getDozer().map(po, MenuDto.class));
		}
		pageDto.setResult(dtoList);
		return pageDto;
	}

}
